package inits

import (
	"course/config"
	"course/global"
	"fmt"
	"github.com/streadway/amqp"
)

func InitRabbitMq() {

	//获取connection
	r := config.Conf.Rabbit
	conn, err := amqp.Dial(fmt.Sprintf("amqp://%s:%s@%s:5672/%s", r.Username, r.Password, r.Host, r.Vhost))
	if err != nil {
		panic("Failed to connect to RabbitMQ")
	}
	//获取channel
	global.MQ, err = conn.Channel()

	if err != nil {
		panic("Failed to open a channel")
	}

	fmt.Println("Connected to RabbitMQ")

}
